this.BX=this.BX||{};this.BX.UI=this.BX.UI||{};(function(e,s,i,l,t){"use strict";var a=babelHelpers.classPrivateFieldLooseKey("id");var r=babelHelpers.classPrivateFieldLooseKey("items");var o=babelHelpers.classPrivateFieldLooseKey("menu");var b=babelHelpers.classPrivateFieldLooseKey("bindElement");var n=babelHelpers.classPrivateFieldLooseKey("draggable");var c=babelHelpers.classPrivateFieldLooseKey("promise");var d=babelHelpers.classPrivateFieldLooseKey("closeResolver");var v=babelHelpers.classPrivateFieldLooseKey("maxVisibleItems");var u=babelHelpers.classPrivateFieldLooseKey("resolveWithCancel");var p=babelHelpers.classPrivateFieldLooseKey("resolveWithItems");var h=babelHelpers.classPrivateFieldLooseKey("getItemById");var P=babelHelpers.classPrivateFieldLooseKey("createMenu");var L=babelHelpers.classPrivateFieldLooseKey("getSaveItem");var F=babelHelpers.classPrivateFieldLooseKey("getCancelItem");var H=babelHelpers.classPrivateFieldLooseKey("save");var f=babelHelpers.classPrivateFieldLooseKey("cancel");var m=babelHelpers.classPrivateFieldLooseKey("getMenuItem");var B=babelHelpers.classPrivateFieldLooseKey("getVisibleSectionTitleItem");var y=babelHelpers.classPrivateFieldLooseKey("getHiddenSectionTitleItem");var g=babelHelpers.classPrivateFieldLooseKey("initDraggable");var I=babelHelpers.classPrivateFieldLooseKey("saveItemsFromMenu");var O=babelHelpers.classPrivateFieldLooseKey("getItemNode");var E=babelHelpers.classPrivateFieldLooseKey("getHiddenSectionTitleNode");var j=babelHelpers.classPrivateFieldLooseKey("adjustMaxVisibleItems");class M extends i.EventEmitter{constructor(e){super();Object.defineProperty(this,j,{value:T});Object.defineProperty(this,E,{value:J});Object.defineProperty(this,O,{value:G});Object.defineProperty(this,I,{value:R});Object.defineProperty(this,g,{value:V});Object.defineProperty(this,y,{value:x});Object.defineProperty(this,B,{value:A});Object.defineProperty(this,m,{value:D});Object.defineProperty(this,f,{value:X});Object.defineProperty(this,H,{value:w});Object.defineProperty(this,F,{value:_});Object.defineProperty(this,L,{value:S});Object.defineProperty(this,P,{value:N});Object.defineProperty(this,h,{value:U});Object.defineProperty(this,p,{value:C});Object.defineProperty(this,u,{value:K});Object.defineProperty(this,a,{writable:true,value:void 0});Object.defineProperty(this,r,{writable:true,value:void 0});Object.defineProperty(this,o,{writable:true,value:void 0});Object.defineProperty(this,b,{writable:true,value:void 0});Object.defineProperty(this,n,{writable:true,value:void 0});Object.defineProperty(this,c,{writable:true,value:void 0});Object.defineProperty(this,d,{writable:true,value:void 0});Object.defineProperty(this,v,{writable:true,value:0});babelHelpers.classPrivateFieldLooseBase(this,a)[a]=s.Type.isStringFilled(e.id)?e.id:"settings-popup-"+Math.random().toString().substring(2);babelHelpers.classPrivateFieldLooseBase(this,r)[r]=e.items;babelHelpers.classPrivateFieldLooseBase(this,b)[b]=e.bindElement;babelHelpers.classPrivateFieldLooseBase(this,v)[v]=Number(e.maxVisibleItems);babelHelpers.classPrivateFieldLooseBase(this,P)[P]();this.setEventNamespace("BX.UI.MenuConfigurable.Menu")}open(e){var s;if(e){var i;(i=babelHelpers.classPrivateFieldLooseBase(this,o)[o])==null?void 0:i.getPopupWindow().setBindElement(e)}(s=babelHelpers.classPrivateFieldLooseBase(this,o)[o])==null?void 0:s.show();if(!babelHelpers.classPrivateFieldLooseBase(this,c)[c]){babelHelpers.classPrivateFieldLooseBase(this,c)[c]=new Promise((e=>{babelHelpers.classPrivateFieldLooseBase(this,d)[d]=e}))}return babelHelpers.classPrivateFieldLooseBase(this,c)[c]}close(){babelHelpers.classPrivateFieldLooseBase(this,P)[P]();babelHelpers.classPrivateFieldLooseBase(this,u)[u]()}setItems(e){babelHelpers.classPrivateFieldLooseBase(this,r)[r]=e;return this}getItemsFromMenu(){const e=[];let i=false;babelHelpers.classPrivateFieldLooseBase(this,o)[o].itemsContainer.querySelectorAll(".menu-configurable-item").forEach((l=>{if(l.classList.contains("menu-configurable-hidden-section-title")){i=true}const t=l.dataset.id;const a=babelHelpers.classPrivateFieldLooseBase(this,h)[h](t);if(a){const l=s.Runtime.clone(a);l.isHidden=i;e.push(l)}}));return e}}function K(){babelHelpers.classPrivateFieldLooseBase(this,c)[c]=null;if(babelHelpers.classPrivateFieldLooseBase(this,d)[d]){babelHelpers.classPrivateFieldLooseBase(this,d)[d]({isCanceled:true})}babelHelpers.classPrivateFieldLooseBase(this,d)[d]=null}function C(){babelHelpers.classPrivateFieldLooseBase(this,c)[c]=null;if(babelHelpers.classPrivateFieldLooseBase(this,d)[d]){babelHelpers.classPrivateFieldLooseBase(this,d)[d]({items:babelHelpers.classPrivateFieldLooseBase(this,r)[r]})}babelHelpers.classPrivateFieldLooseBase(this,d)[d]=null}function U(e){return babelHelpers.classPrivateFieldLooseBase(this,r)[r].find((s=>s.id===e))}function N(e){if(babelHelpers.classPrivateFieldLooseBase(this,o)[o]){babelHelpers.classPrivateFieldLooseBase(this,o)[o].destroy();babelHelpers.classPrivateFieldLooseBase(this,n)[n]=null}const s=[];s.push(babelHelpers.classPrivateFieldLooseBase(this,B)[B]());const i=babelHelpers.classPrivateFieldLooseBase(this,r)[r].filter((e=>!e.isHidden));const t=babelHelpers.classPrivateFieldLooseBase(this,r)[r].filter((e=>e.isHidden));i.forEach((e=>{s.push(babelHelpers.classPrivateFieldLooseBase(this,m)[m](e))}));s.push(babelHelpers.classPrivateFieldLooseBase(this,y)[y]());t.forEach((e=>{s.push(babelHelpers.classPrivateFieldLooseBase(this,m)[m](e))}));s.push(babelHelpers.classPrivateFieldLooseBase(this,L)[L]());s.push(babelHelpers.classPrivateFieldLooseBase(this,F)[F]());babelHelpers.classPrivateFieldLooseBase(this,o)[o]=l.MenuManager.create({id:babelHelpers.classPrivateFieldLooseBase(this,a)[a],items:s,bindElement:e!=null?e:babelHelpers.classPrivateFieldLooseBase(this,b)[b],events:{onClose:this.close.bind(this)}});babelHelpers.classPrivateFieldLooseBase(this,g)[g]();return babelHelpers.classPrivateFieldLooseBase(this,o)[o]}function S(){return{text:s.Loc.getMessage("UI_JS_MENU_CONFIGURABLE_SAVE"),onclick:babelHelpers.classPrivateFieldLooseBase(this,H)[H].bind(this)}}function _(){return{text:s.Loc.getMessage("UI_JS_MENU_CONFIGURABLE_CANCEL"),onclick:babelHelpers.classPrivateFieldLooseBase(this,f)[f].bind(this)}}function w(){const e=new i.BaseEvent;this.emit("Save",e);if(e.isDefaultPrevented()){return}babelHelpers.classPrivateFieldLooseBase(this,I)[I]();babelHelpers.classPrivateFieldLooseBase(this,p)[p]();babelHelpers.classPrivateFieldLooseBase(this,P)[P]()}function X(){const e=new i.BaseEvent;this.emit("Cancel",e);if(e.isDefaultPrevented()){return}this.close()}function D(e){return{id:e.id,text:e.text,html:e.html,className:"menu-configurable-item",dataset:{id:e.id}}}function A(){return{delimiter:true,html:"<span>"+s.Loc.getMessage("UI_JS_MENU_CONFIGURABLE_VISIBLE")+"</span>",className:"menu-configurable-visible-section-title menu-configurable-delimiter-item"}}function x(){return{delimiter:true,html:"<span>"+s.Loc.getMessage("UI_JS_MENU_CONFIGURABLE_HIDDEN")+"</span>",className:"menu-configurable-hidden-section-title menu-configurable-delimiter-item menu-configurable-item"}}function V(){babelHelpers.classPrivateFieldLooseBase(this,n)[n]=new t.Draggable({container:babelHelpers.classPrivateFieldLooseBase(this,o)[o].itemsContainer,draggable:".menu-configurable-item",dragElement:".menu-popup-item-icon",type:t.Draggable.MOVE});babelHelpers.classPrivateFieldLooseBase(this,n)[n].subscribe("end",babelHelpers.classPrivateFieldLooseBase(this,j)[j].bind(this))}function R(){this.setItems(this.getItemsFromMenu())}function G(e){return babelHelpers.classPrivateFieldLooseBase(this,o)[o].itemsContainer.querySelector('.menu-configurable-item[data-id="'+e.id+'"]')}function J(){return babelHelpers.classPrivateFieldLooseBase(this,o)[o].itemsContainer.querySelector(".menu-configurable-hidden-section-title")}function T(){if(babelHelpers.classPrivateFieldLooseBase(this,v)[v]<=0){return}const e=this.getItemsFromMenu();const i=e.filter((e=>!e.isHidden));const l=i.length;const t=babelHelpers.classPrivateFieldLooseBase(this,E)[E]();if(t&&l>babelHelpers.classPrivateFieldLooseBase(this,v)[v]){for(let e=babelHelpers.classPrivateFieldLooseBase(this,v)[v];e<l;e++){const l=i[e];const a=babelHelpers.classPrivateFieldLooseBase(this,O)[O](l);if(a){s.Dom.insertAfter(a,t)}}}}e.Menu=M})(this.BX.UI.MenuConfigurable=this.BX.UI.MenuConfigurable||{},BX,BX.Event,BX.Main,BX.UI.DragAndDrop);
//# sourceMappingURL=menu-configurable.bundle.map.js